home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickTime / Programming Stuff / Documentation / develop articles / develop Issue 23 / Internet Config / IC 1.1 / ICAppSourceKit1.1 / ICGlobals.p < prev    next >
Encoding:
Text File  |  1995-04-22  |  3.7 KB  |  140 lines  |  [TEXT/PJMM]

  1. unit ICGlobals;
  2.  
  3. interface
  4.  
  5.     uses
  6.         ICTypes;
  7.  
  8.     const
  9.         M_File = 129;
  10.         M_Edit = 130;
  11.         M_Install = 131;
  12.         M_Windows = 132;
  13.  
  14.     const
  15.         EM_Undo = 1;
  16.         (* *)
  17.         EM_Cut = 3;
  18.         EM_Copy = 4;
  19.         EM_Paste = 5;
  20.         EM_Clear = 6;
  21.         EM_SelectAll = 7;
  22.  
  23.     const
  24.         FM_New = 1;
  25.         FM_Open = 2;
  26.         FM_OpenInternetPreferences = 3;
  27.         (* *)
  28.         FM_Close = 5;
  29.         FM_Save = 6;
  30.         FM_SaveAs = 7;
  31.         (* *)
  32.         FM_Quit = 9;
  33.  
  34.     const
  35.         IM_Install = 1;
  36.         IM_Save = 2;
  37.         IM_Remove = 3;
  38.  
  39.     const                                    { Other OS constants, probably declared somewhere now }
  40.         kSysEnvironsVersion = 1;
  41.         kOSEvent = app4Evt;                {event used by MultiFinder}
  42.         kSuspendResumeMessage = 1;    {high byte of suspend/resume event message}
  43.         kResumeMask = 1;                    {bit of message field for resume vs. suspend}
  44.         kMouseMovedMessage = $FA;    {high byte of mouse-moved event message}
  45.         kNoEvents = 0;                        {no events mask}
  46.  
  47.     var  { set up by InitSystemGlobals }
  48.         system7: boolean;
  49.         has_appleEvents: boolean;
  50.         has_findfolder: boolean;
  51.         has_aliasMgr: boolean;
  52.         has_newStdFile: boolean;
  53.         has_HelpMgr: boolean;
  54.         has_colorQD: boolean;
  55.         has_components: boolean;
  56.         app_resfile: integer;
  57.         app_fs: FSSpec;
  58.         in_foreground: boolean;
  59.         quitNow: boolean;
  60.         app_version: VersRec;
  61.  
  62.     procedure InitGlobals;
  63.  
  64.     function InForeground: boolean;
  65.  
  66.     type
  67.         icAction = (acDoThis, acInstallComponent, acOpenWindow, acNewDocument, acOpenDocument, acCloseWindow, acSave, {}
  68.             acQuit, acStartApplication, acGetExample, acChooseApplication, acRemoveComponent);
  69.  
  70.     procedure DisplayError (action: icAction; err: OSErr);
  71.  
  72. implementation
  73.  
  74.     uses
  75.         Processes, Components, GestaltEqu;
  76.  
  77.     procedure InitGlobals;
  78.         var
  79.             oe: OSErr;
  80.             gv: longInt;
  81.             pb: FCBPBRec;
  82.             sysenv: sysEnvRec;
  83.             versh: VersRecHndl;
  84.     begin
  85.         app_resfile := CurResFile;
  86.         pb.ioNamePtr := @app_fs.name;
  87.         pb.ioVRefNum := 0;
  88.         pb.ioRefNum := app_resfile;
  89.         pb.ioFCBIndx := 0;
  90.         oe := PBGetFCBInfo(@pb, false);
  91.         app_fs.vRefNum := pb.ioFCBVRefNum;
  92.         app_fs.parID := pb.ioFCBParID;
  93.         has_colorqd := (SysEnvirons(1, sysEnv) = noErr) & sysenv.hasColorQD; { Gestalt has a bug that causes hasColourQD to always be set }
  94.         system7 := (Gestalt(gestaltSystemVersion, gv) = noErr) & (gv >= $0700);
  95.         has_AppleEvents := (Gestalt(gestaltAppleEventsAttr, gv) = noErr) & (BTST(gv, gestaltAppleEventsPresent));
  96.         has_findfolder := (Gestalt(gestaltFindFolderAttr, gv) = noErr) & (BTST(gv, gestaltFindFolderPresent));
  97.         has_newStdFile := (Gestalt(gestaltStandardFileAttr, gv) = noErr) & (BTST(gv, gestaltStandardFile58));
  98.         has_HelpMgr := (Gestalt(gestaltHelpMgrAttr, gv) = noErr) & (BTST(gv, gestaltHelpMgrPresent));
  99.         has_aliasMgr := (Gestalt(gestaltAliasMgrAttr, gv) = noErr) & (BTST(gv, gestaltAliasMgrPresent));
  100.         has_components := (Gestalt(gestaltComponentMgr, gv) = noErr) & (gv > 0);
  101.         versh := VersRecHndl(Get1Resource('vers', 1));
  102.         if versh <> nil then begin
  103.             app_version := versh^^;
  104.         end
  105.         else begin
  106.             app_version.numericVersion.version := 0;
  107.             app_version.countryCode := 0;
  108.             app_version.shortVersion := '';
  109.         end; (* if *)
  110.     end;
  111.  
  112.     function InForeground: boolean;
  113.         var
  114.             gv: longInt;
  115.             ourpsn, frontpsn: ProcessSerialNumber;
  116.             front: boolean;
  117.     begin
  118.         if (Gestalt(gestaltOSAttr, gv) = noErr) & (BTST(gv, gestaltLaunchControl)) then begin
  119.             if (GetCurrentProcess(ourpsn) = noErr) & (GetFrontProcess(frontpsn) = noErr) then begin
  120.                 if SameProcess(ourpsn, frontpsn, front) = noErr then
  121.                     in_foreground := front;
  122.             end;
  123.         end;
  124.         InForeground := in_foreground;
  125.     end;
  126.  
  127.     procedure DisplayError (action: icAction; err: OSErr);
  128.         var
  129.             junk: integer;
  130.             tmp: Str255;
  131.     begin
  132.         if (err <> noErr) and (err <> userCanceledErr) then begin
  133.             InitCursor;
  134.             GetIndString(tmp, 131, ord(action) + 1);
  135.             ParamText(tmp, StringOf(err : 1), '', '');
  136.             junk := StopAlert(140, nil);
  137.         end; (* if *)
  138.     end; (* DisplayError *)
  139.  
  140. end. (* ICGlobals *)